package org.exhaust.framework.net.common.protocol.encoder;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;
import org.exhaust.framework.net.common.protocol.BaseFrame;

@Slf4j
@Deprecated
public class TcpFrameToBytesEncoder extends MessageToByteEncoder<BaseFrame> {
    @Override
    protected void encode(ChannelHandlerContext ctx, BaseFrame msg, ByteBuf out) throws Exception {
        byte[] data = msg.encode();
        String hexDump = ByteBufUtil.hexDump(data);
        log.info("encoded msg:{}", hexDump);
        out.writeBytes(data);
    }
}
